# valgrind --leak-check=full --track-origins=yes
# LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=raft-kv-1.prof 
coredump:  echo './core-%e-%p-%t' > /proc/sys/kernel/core_pattern
# prometheus: /opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml
# redis-exporter: /opt/redis_exporter/redis_exporter -redis.addr localhost:6379 
# grafana: /opt/grafana/bin/grafana server   --config=/opt/grafana/conf/defaults.ini --homepath=/opt/grafana


nameserver: ./bin/nameserver --confPath=$(realpath conf/startup.yaml)
admin: ./bin/admin --confPath=$(realpath conf/startup.yaml)

redis-master0: redis-server $(yq eval '0 as $index | .master.confpath + " --port " + .master.port[$index] + " --dbfilename " + .master.dbfilename[$index]' $(realpath conf/startup.yaml))
redis-slave0 : redis-server $(yq eval '0 as $index |  .slave.confpath + " --port " +  .slave.port[$index] + " --slaveof 127.0.0.1 " + .master.port[$index] + " --dbfilename " + .slave.dbfilename[$index]' $(realpath conf/startup.yaml))
broker0: ./bin/broker  $(yq eval '0 as $index | "--uri=tcp://127.0.0.1:" + .nameserver.port + ":" + .broker.port[$index] + ":" + .master.port[$index]' $(realpath conf/startup.yaml))

redis-master1: redis-server $(yq eval '1 as $index | .master.confpath + " --port " + .master.port[$index] + " --dbfilename " + .master.dbfilename[$index]' $(realpath conf/startup.yaml))
redis-slave1 : redis-server $(yq eval '1 as $index |  .slave.confpath + " --port " +  .slave.port[$index] + " --slaveof 127.0.0.1 " + .master.port[$index] + " --dbfilename " + .slave.dbfilename[$index]' $(realpath conf/startup.yaml))
broker1: ./bin/broker  $(yq eval '1 as $index | "--uri=tcp://127.0.0.1:" + .nameserver.port + ":" + .broker.port[$index] + ":" + .master.port[$index]' $(realpath conf/startup.yaml))

redis-master2: redis-server $(yq eval '2 as $index | .master.confpath + " --port " + .master.port[$index] + " --dbfilename " + .master.dbfilename[$index]' $(realpath conf/startup.yaml))
redis-slave2 : redis-server $(yq eval '2 as $index |  .slave.confpath + " --port " +  .slave.port[$index] + " --slaveof 127.0.0.1 " + .master.port[$index] + " --dbfilename " + .slave.dbfilename[$index]' $(realpath conf/startup.yaml))
broker2: ./bin/broker  $(yq eval '2 as $index | "--uri=tcp://127.0.0.1:" + .nameserver.port + ":" + .broker.port[$index] + ":" + .master.port[$index]' $(realpath conf/startup.yaml))


producer0: ./bin/producer --confPath=$(realpath conf/startup.yaml) --id 0 --index 0
consumer0: ./bin/consumer --confPath=$(realpath conf/startup.yaml) --id 0 --index 0

# producer1: ./bin/producer --confPath=$(realpath conf/startup.yaml) --id 1 --index 0
consumer1: ./bin/consumer --confPath=$(realpath conf/startup.yaml) --id 1 --index 0

# producer2: ./bin/producer --confPath=$(realpath conf/startup.yaml) --id 2 --index 0
consumer2: ./bin/consumer --confPath=$(realpath conf/startup.yaml) --id 2 --index 0

